/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package cn.ac.iie.di.ftp;

import cn.ac.iie.di.global.GlobalParas;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Austin
 */
public class FtpDownloadFile implements Runnable {

    static org.apache.log4j.Logger logger = null;

    static {
        logger = org.apache.log4j.Logger.getLogger(FtpDownloadFile.class.getName());
    }

    @Override
    public void run() {
        String ip = GlobalParas.FTP_IPPORT.split(":")[0];
        int port = Integer.valueOf(GlobalParas.FTP_IPPORT.split(":")[1]);
        String name = GlobalParas.FTP_NAMEPWD.split(":")[0];
        String pwd = GlobalParas.FTP_NAMEPWD.split(":")[1];
        String downPath = GlobalParas.FTP_PATH;
        logger.info(ip + " FtpTools downFile start");
        while (true) {
            try {
                Long startTime = System.currentTimeMillis();
                List<String> file = new FtpTools().downFile(ip, port, name, pwd, downPath, GlobalParas.ORI_GWX);

//                logger.info();
                if (file.size() > 0) {
//                    new FtpTools().uploadDwdFile(ip, port, name, pwd, downPath, file);
                    new FtpTools().deleteFile(ip, port, name, pwd, downPath, file);
                }
                Long endTime = System.currentTimeMillis();
                logger.info("download And delete FileNum " + file.size() + " RunTime is " + (endTime - startTime));
                Thread.sleep(3000);
            } catch (InterruptedException ex) {
                Logger.getLogger(FtpDownloadFile.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }

}
